package com.muyu.danmo.controller;

import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoTrainingType;
import com.muyu.danmo.service.IDanmoTrainingTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * 培训班类型Controller
 *
 * @author yangle
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/trainingType")
public class DanmoTrainingTypeController extends BaseController
{
    @Autowired
    private IDanmoTrainingTypeService danmoTrainingTypeService;

    /**
     * 查询培训班类型列表
     */
//    @RequiresPermissions("system:type:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoTrainingType>> list(DanmoTrainingType danmoTrainingType)
    {
        startPage();
        List<DanmoTrainingType> list = danmoTrainingTypeService.selectDanmoTrainingTypeList(danmoTrainingType);
        return getDataTable(list);
    }

    /**
     * 导出培训班类型列表
     */
//    @RequiresPermissions("system:type:export")
    @Log(title = "培训班类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoTrainingType danmoTrainingType)
    {
        List<DanmoTrainingType> list = danmoTrainingTypeService.selectDanmoTrainingTypeList(danmoTrainingType);
        ExcelUtil<DanmoTrainingType> util = new ExcelUtil<DanmoTrainingType>(DanmoTrainingType.class);
        util.exportExcel(response, list, "培训班类型数据");
    }

    /**
     * 获取培训班类型详细信息
     */
//    @RequiresPermissions("system:type:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoTrainingTypeService.selectDanmoTrainingTypeById(id));
    }

    /**
     * 新增培训班类型
     */
//    @RequiresPermissions("system:type:add")
    @Log(title = "培训班类型", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoTrainingType danmoTrainingType)
    {
        return toAjax(danmoTrainingTypeService.insertDanmoTrainingType(danmoTrainingType));
    }

    /**
     * 修改培训班类型
     */
//    @RequiresPermissions("system:type:edit")
    @Log(title = "培训班类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoTrainingType danmoTrainingType)
    {
        return toAjax(danmoTrainingTypeService.updateDanmoTrainingType(danmoTrainingType));
    }

    /**
     * 删除培训班类型
     */
//    @RequiresPermissions("system:type:remove")
    @Log(title = "培训班类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoTrainingTypeService.deleteDanmoTrainingTypeByIds(ids));
    }
}
